package main

import (
	"fmt"
	"os"
	"time"
)

func main() {
	ticker := time.NewTicker(time.Second * 3)

	fmt.Println("倒计时发射，按键可随时取消")

	num := 5

	chan_stdin := make(chan string)

	go func(out chan<- string) {
		data := make([]byte, 10)
		//此处会阻塞
		os.Stdin.Read(data)
		out <- "cancel"
	}(chan_stdin)

	for {
		select {
		case <-ticker.C:
			fmt.Println(num)
			num--
		case <-chan_stdin:
			fmt.Println("取消发射")
			return
		}
		if num == 0 {
			ticker.Stop()
			break
		}
	}
}
